# demo03_subprocess.py
import subprocess
# subprocess.run(["ls", "/home"])  # ls /home
# subprocess.run(["echo", "$HOME"])  # echo $HOME
# subprocess.run("ls /home", shell=True)
# subprocess.run("echo $HOME", shell=True)

# run函数返回值
# args: 进行执行的命令
# returncode: 类似于shell中的$?
#             上一条命令执行结果,成功为0，否则为非0
data = subprocess.run("ls /home", shell=True)
print("data:", data)
print(data.args, data.returncode)  # int 0
# CompletedProcess(args='ls /home', returncode=0)